using System;
using System.Collections;
using System.Collections.Generic;
using EventApp.Lib.Helper;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Criterion;

namespace EventApp.Lib.Repository
{
    public class DataRepository<T> : IDataRepository<T>
    {

        public ISession RepositorySession { get; set; }

        public DataRepository(ISessionBuilder sessionBuilder)
        {
            this.RepositorySession = sessionBuilder.GetSession();
        }

        #region IDataRepository<T> Members

        public void Add(T itemToSave)
        {
            this.RepositorySession.Save(itemToSave);
        }

        public void Delete(T itemToDelete)
        {
            this.RepositorySession.Delete(itemToDelete);
        }

        public IList GetMulti( ICriteria criteria)
        {
            return criteria.List();
        }

        public void BeginTransaction()
        {
            this.RepositorySession.BeginTransaction();
        }

        public void CommitTransaction()
        {
            this.RepositorySession.Transaction.Commit();
        }

        public void RollBackTransaction()
        {
            this.RepositorySession.Transaction.Rollback();
        }

        #endregion
    }
}